package edu.gyc.util;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class AverageTask {

    public static void average(Integer[] l, int n) {
        int len = l.length % n == 0 ? l.length / n : l.length / n + 1;
        for (int i = 0; i < n; i++) {
            int start = i * len;
            for (int j = start; j < start+len; j++) {
                if (j + 1 <= l.length) {
                    System.out.print(" " + l[j]);
                }
            }
            System.out.println();
        }
    }
//泛型方法
    public static <T> List<List<T>> average(List<T> l, int n) {
        int len = l.size() % n == 0 ? l.size() / n : l.size() / n + 1;
        List<List<T>> lists = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int start = i * len;
            List<T> list = new ArrayList<T>();
            for (int j = start; j < start+len; j++) {
                if (j + 1 <= l.size()) {
                   // System.out.print(" " + l[j]);
                    list.add(l.get(j));
                }
            }
            //System.out.println();
            lists.add(list);
        }
        return lists;
    }
    public static void main(String[] args) {
       /* Integer[] l = new Integer[37];
        for (int i = 1; i <= 37; i++) {
            l[i - 1] = i;
        }
        average(l, 6);
        
        */

        List<Integer> list = new ArrayList<>();
        for (int i = 1; i <= 47; i++) {
            list.add(i);
        }

        System.out.println(average(list,6));

        List<String > list1 = new ArrayList<>();
        for (int i = 1; i <= 47; i++) {
            list1.add(UUID.randomUUID().toString());
        }

        System.out.println(average(list1,6));
    }

 
}
